package nl.weeaboo.sh.danmaku.commands;

import nl.weeaboo.sh.danmaku.ShotModel;
import nl.weeaboo.sh.danmaku.Spell;
import nl.weeaboo.sh.danmaku.SpellBook;
import nl.weeaboo.sh.danmaku.Universe;

public class TAngleTo extends Spell {

	private float targetAngle;
	private float angleInc;
	
	public TAngleTo(float angle, float ainc) {
		this.targetAngle = angle;
		this.angleInc = Math.abs(ainc);
	}
	protected TAngleTo(TAngleTo t) {
		super(t);		
		
		targetAngle = t.targetAngle;
		angleInc = t.angleInc;
	}
	
	public TAngleTo clone() {
		return new TAngleTo(this);
	}
	
	@Override
	public void step(Universe u, SpellBook sb, ShotModel s) {
		float da = targetAngle - s.getAngle();
		if (Math.abs(da) < angleInc) {
			s.setAngle(targetAngle);
			finish();
		} else if (da >= 0 && da <= 256f) {
			s.setAngle(s.getAngle() + angleInc);
		} else {
			s.setAngle(s.getAngle() - angleInc);
		}
	}
	
}
